fn get_video_files_with_full_path(
  folder_path: &std::path::Path,
) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> {
  let mut video_files: Vec<(String, String)> = Vec::new();
  let video_extensions = [
    "mp4", "avi", "mkv", "mov", "wmv", "flv", "webm", "m4v", "3gp", "mpg",
    "mpeg", "ts", "mts", "m2ts", "vob", "ogv", "ogg", "drc", "gifv", "mng",
    "avi", "mov", "qt", "wmv", "yuv", "rm", "rmvb", "asf", "amv", "m4p", "m4v",
    "svi", "3g2", "mxf", "roq", "nsv",
  ];

  let entries = std::fs::read_dir(folder_path)?;

  for entry in entries {
    let entry = entry?;
    let path = entry.path();
    if path.is_file()
      && let Some(extension) = path.extension()
    {
      let ext = extension.to_string_lossy().to_lowercase();
      if video_extensions.contains(&ext.as_str()) {
        let file_path = path.to_string_lossy().to_string();
        if let Some(file_name) = path.file_name() {
          let name = file_name.to_string_lossy().to_string();
          video_files.push((name, file_path));
        }
      }
    }
  }

  Ok(video_files)
}

fn main() {
  let folder_path = std::path::Path::new(
    "/home/timly/Desktop/gitworkspace/rust_stream_media_m3u8/demo3_read_file/vedios",
  ); // 替换为你的文件夹路径

  match get_video_files_with_full_path(folder_path) {
    Ok(files) => {
      if files.is_empty() {
        println!("未找到视频文件");
      } else {
        println!("找到的视频文件:");
        for file in files {
          println!("{:?}", file);
        }
      }
    }
    Err(e) => {
      eprintln!("读取文件夹时出错: {}", e);
    }
  }
}
